<template>
    <div class="real-time" style="margin: 110px 15px 15px 15px;"> 
        <el-collapse v-model="activeNames">
            <el-collapse-item v-for="(item, index) in realData" :key="index" :title="item.channelName" :name="index"> 
                <el-card class='box-card' style="margin-top: 10px;margin-bottom: 20px;">
                    <div class='title'>
                        <div class="header">
                            <div>
                                <span>{{$t('approvalDetail.riskTime')}}：</span>
                                <!-- <span>{{newData}}</span> -->
                                <el-date-picker
                                v-model="currDate"
                                type="date"
                                value-format="yyyy-MM-dd"
                                :placeholder="$t('realTimeData.choiceDate')">
                                </el-date-picker>
                                <el-button type="primary" @click='search'>
                                    {{$t('btn.query')}}
                                </el-button>
                            </div>
                            <div class="title-right">
                                <div style="margin-right: 20px;">
                                    <el-tooltip :content="$t('synManager.firstOverRate')" placement="top">
                                    <span>{{$t('realTimeData.sameDayfirstOver')}}：</span>
                                    </el-tooltip>
                                    <span>{{item.firstOverRate}}%</span>
                                </div>
                                <div>
                                    <span>{{$t('realTimeData.realTimefirstOver')}}：</span>
                                    <span>{{item.realTimeFirstOverRate}}%</span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="data-table">
                        <div class="data-item">
                            <div>{{$t('group.name')}}</div>
                            <div>{{$t('realTimeData.sum')}}</div>
                            <div>{{$t('realTimeData.orderNum')}}</div>
                        </div>
                        <div class="data-item">
                            <el-tooltip :content="$t('synManager.meaning1')" placement="top">
                                <div>{{$t('realTimeData.data1')}}</div>
                            </el-tooltip>
                            <div>{{item.realTimeReports[0].money}}</div>
                            <div style="border-right: none;"></div>
                        </div>
                        <div class="data-item">
                            <el-tooltip :content="$t('synManager.meaning2')" placement="top">
                                <div>{{$t('realTimeData.data2')}}</div>
                            </el-tooltip>
                            <div>{{item.realTimeReports[1].money}}</div>
                            <div style="border-right: none;">{{item.realTimeReports[1].orderQuantity}}</div>
                        </div>
                        <div class="data-item">
                            <el-tooltip :content="$t('synManager.meaning3')" placement="top">
                                <div>{{$t('realTimeData.data3')}}</div>
                            </el-tooltip>
                            <div>{{item.realTimeReports[2].money}}</div>
                            <div></div>
                        </div>
                        <div class="data-item">
                            <el-tooltip :content="$t('synManager.meaning4')" placement="top">
                                <div>{{$t('realTimeData.data4')}}</div>
                            </el-tooltip>
                            <div>{{item.realTimeReports[5].money}}</div>
                            <div>{{item.realTimeReports[5].orderQuantity}}</div>
                        </div>
                        <div class="data-item">
                            <el-tooltip :content="$t('synManager.meaning5')" placement="top">
                                <div>{{$t('realTimeData.data5')}}</div>
                            </el-tooltip>
                            <div>{{item.realTimeReports[3].money}}</div>
                            <div>{{item.realTimeReports[3].orderQuantity}}</div>
                        </div>
                        <div class="data-item">
                            <el-tooltip :content="$t('synManager.meaning6')" placement="top">
                                <div>{{$t('realTimeData.data6')}}</div>
                            </el-tooltip>
                            <div>{{item.realTimeReports[4].money}}</div>
                            <div>{{item.realTimeReports[4].orderQuantity}}</div>
                        </div>
                        <div class="data-item">
                            <el-tooltip :content="$t('synManager.meaning7')" placement="top">
                                <div>{{$t('realTimeData.data7')}}</div>
                            </el-tooltip>
                            <div>{{item.realTimeReports[6].money}}</div>
                            <div>{{item.realTimeReports[6].orderQuantity}}</div>
                        </div>
                        <div class="data-item">
                            <el-tooltip :content="$t('synManager.meaning8')" placement="top">
                                <div>{{$t('realTimeData.data8')}}</div>
                            </el-tooltip>
                            <div>{{item.realTimeReports[7].money}}</div>
                            <div>{{item.realTimeReports[7].orderQuantity}}</div>
                        </div>
                        <div class="data-item">
                            <el-tooltip :content="$t('synManager.meaning9')" placement="top">
                                <div>{{$t('realTimeData.data9')}}</div>
                            </el-tooltip>
                            <div>{{item.realTimeReports[8].money}}</div>
                            <div>{{item.realTimeReports[8].orderQuantity}}</div>
                        </div>
                        <div class="data-item">
                            <el-tooltip :content="$t('synManager.meaning10')" placement="top">
                                <div style="border-right: none;">{{$t('realTimeData.data10')}}</div>
                            </el-tooltip>
                            <div style="border-right: none;">{{item.realTimeReports[9].money}}</div>
                            <div style="border-right: none;">{{item.realTimeReports[9].orderQuantity}}</div>
                        </div>
                    </div>
                </el-card>
            </el-collapse-item>
        </el-collapse>
    </div>
</template>

<script>
    import { mapGetters } from "vuex";
    import { realTime, getHistoryTime } from 'api/synManager/realTimeData/index'
    export default {
        data() {
            return {
                currDate: '',
                activeNames: [0],
                newData: '',
                realData: []
            }
        },
        computed: { 
            ...mapGetters([ 'username' ])
        },
        created() {
            this.getTime();
            this.getList();
        },
        methods: {
            // 查询
            search() {
                if (this.currDate === null || this.currDate === '' || this.currDate === undefined || this.currDate === this.newData) {
                    this.getList();
                } else {
                    let obj = {};
                    obj.currDate = this.currDate;
                    getHistoryTime(obj)
                    .then(res => {
                        res.data.forEach(i => {
                            i.realTimeReports.forEach(item => {
                                let re = /(?=(?!\b)(\d{3})+$)/g;
                                let str = String(item.money)
                                item.money =  str.replace(re, ',');
                            })
                        })
                        this.realData = res.data
                    })
                }
            },
            getList() {
                let obj = {};
                obj.userName = this.username
                realTime(obj)
                .then(res => {
                    res.data.forEach(i => {
                        i.realTimeReports.forEach(item => {
                            let re = /(?=(?!\b)(\d{3})+$)/g;
                            let str = String(item.money)
                            item.money =  str.replace(re, ',');
                        })
                    })
                    this.realData = res.data
                })
            },
            getTime() {
                let date = new Date();
                let seperator1 = "-";
                let year = date.getFullYear();
                let month = date.getMonth() + 1;
                let strDate = date.getDate();
                if (month >= 1 && month <= 9) {
                    month = "0" + month;
                }
                if (strDate >= 0 && strDate <= 9) {
                    strDate = "0" + strDate;
                }
                this.newData = year + seperator1 + month + seperator1 + strDate;
            }
        }
    }
</script>

<style scoped lang='scss'>
.box-card {
  width: 95%;
  overflow: auto;
  margin-left: 2.5%;
  margin-right: 2.5%;
}
.title {
  min-width: 800px;
  line-height: 30px;
  font-size: 16px;
  display: flex;
  align-items: center;
  font-weight: bold;
}
.title:before{
  display: block;
  content: "";
  width: 3px;
  height: 16px;
  background-color: #309afe;
}
.title:before {
  margin-right: 8px;
}
::before {
  box-sizing: inherit;
  -webkit-tap-highlight-color: transparent;
}
.header {
    width: 100%; 
    display: flex;
    justify-content: space-between;
}
.title-right {
    cursor: pointer;
    display: flex;
}
.data-table {
    width: 100%;
    min-width: 800px;
    border: 1px solid #ccc;
    display: flex;
    text-align: center;
    margin-top: 10px;
}
.data-item {
    flex: 1;
    font-size: 12px;
    &>div {
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 0 10px;
        height: 100px;
        box-sizing: border-box;
        border-bottom: 1px solid #ccc;
        border-right: 1px solid #ccc;
        &:nth-child(1) {
            height: 90px;
            cursor: pointer;
        }
        &:last-child {
            border-bottom: none;
            height: 160px;
        }
    }
}
.real-time /deep/.el-card__body {
    min-width: 850px;
    padding: 10px;
}
</style>